package com.itheima_04;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class constructorTest {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class clazz = Class.forName("com.itheima_04.Student");
        Constructor[] constructors = clazz.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
        System.out.println("---------------------------------------");
        Class clazz1 = Class.forName("com.itheima_04.Student");
        Constructor[] constructors1 = clazz.getDeclaredConstructors();
        for (Constructor constructor : constructors1) {
            System.out.println(constructor);
        }
        System.out.println("------------------------------------");
        Class clazz2 = Class.forName("com.itheima_04.Student");
        Constructor constructor = clazz2.getConstructor(String.class);
        Student stu = (Student) constructor.newInstance("张三");
       // System.out.println(stu);
        System.out.println("-----------------------------------------");
        Class clazz3= Class.forName("com.itheima_04.Student");
        Constructor declaredConstructor = clazz3.getDeclaredConstructor(int.class);
        declaredConstructor.setAccessible(true);
        Student student1 = (Student) declaredConstructor.newInstance(15);
       // System.out.println(student1);


    }
}
